package com.unionx.unionxuf.controller;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Controller;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unionx.unionxuf.common.ZdyException;
import com.unionx.unionxuf.entity.BillMain;
import com.unionx.unionxuf.entity.BillSub;
import com.unionx.unionxuf.entity.CropDTD;
import com.unionx.unionxuf.entity.ReceivepayManger;
import com.unionx.unionxuf.entity.RmDTD;
import com.unionx.unionxuf.entity.Settlestyle;
import com.unionx.unionxuf.entity.updateDTD;
import com.unionx.unionxuf.service.BillMainService;
import com.unionx.unionxuf.service.BillSubService;
import com.unionx.unionxuf.service.LocalReceivepayManagerService;
import com.unionx.unionxuf.service.LocalSettleService;

@Transactional
@Controller
@RequestMapping(value="/lbs")
public class LocalBillSubController {

	@Autowired
	private BillMainService billmainser;
	@Autowired
	private BillSubService billser;
	@Autowired
	private LocalSettleService ss;
	@Autowired
	private LocalReceivepayManagerService lrs;
	
	
	@Autowired(required = true)
	private DataSourceTransactionManager localtransactionManager;

	DefaultTransactionDefinition def = new DefaultTransactionDefinition();
	
	
	@RequestMapping(value="/save/billmain")
	@ResponseBody
	public Object saveBillmain(HttpServletRequest request,HttpServletResponse response,String dd,String danju,String lsh,String fph,String name,String phone,
			String banka,String youhui,String yuyue,String fptt,String g1,String g2,String g3,String g4,String g5,String g6,String hy,String chuku,String g21,String g22,String g23,String g24,String g25,String g26,String g27,String g28,String g29,String g210,String g211,String g212,String g213,String g214,String g31,String g32,String g33,String g34,String g41,String g42,String g43){
	
		
		
		TransactionStatus status = localtransactionManager.getTransaction(def);
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
		def.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ);

		
	
		
 		Map<String,Object>  map =  new HashMap<String,Object>();
		HttpSession session  = request.getSession();
		String cropid=(String) session.getAttribute("cropid");
		String shoukuanren =(String)session.getAttribute("name");
		try {
			
			BillMain  b = new BillMain();
			b.setDate(dd);
			if(danju==""||danju=="null"||danju==null){
				b.setNo("");
			}else{
				b.setNo(danju);
			}
			if(lsh==""||lsh=="null"||lsh==null){
				b.setSerialno("");
			}else{
				b.setSerialno(lsh);
			}
			if(fph==""||fph=="null"||fph==null){
				b.setInvoiceno("");
			}else{
				b.setInvoiceno(fph);
			}
			b.setCustomer(name);
			if(phone==""||phone=="null"||phone==null){
				b.setTelno("");
			}else{
				b.setTelno(phone);
			}
			if(banka==""||banka=="null"||banka==null){
				b.setCardtime("");
			}else{
				b.setCardtime(banka);
			}
			if(youhui==""||youhui=="null"||youhui==null){
				b.setBillmaincol3("");
			}else{
				b.setBillmaincol3(youhui);
			}
		
			if(yuyue==""||yuyue=="null"||yuyue==null){
				b.setReservatime("");
			}else{
				b.setReservatime(yuyue);
			}
		/*	if(chuku==""||chuku=="null"||chuku==null){
				b.setOutboundorder("");
			}else{
				b.setOutboundorder(chuku);
			}*/
			if(fptt==""||fptt=="null"||fptt==null){
				b.setInvoicehead("");
			}else{
				b.setInvoicehead(fptt);
			}
			
			b.setCropid(cropid);
			b.setZhuangtai("0");
			b.setShenhezhuangtai("0");
			b.setShoukuanren(shoukuanren);
	       int o = billmainser.saveBillmain(b);
			
	    //子表   
			List<BillSub> listbs = new ArrayList<BillSub>();

			String[] str1=g21.split(",");
			String[] str2=g22.split(",");
			String[] str3=g23.split(",");
			String[] str4=g24.split(",");
			String[] str5=g25.split(",");
			String[] str6=g26.split(",");
			String[] str7=g27.split(",");
			String[] str8=g28.split(",");
			String[] str9=g29.split(",");
			String[] str10=g210.split(",");
			String[] str11=g211.split(",");
			String[] str12=g212.split(",");
			String[] str13=g213.split(",");
			String[] str14=g214.split(",");
			
			String[] str15=g1.split(",");
			String[] str16=g2.split(",");
			String[] str17=g3.split(",");
			String[] str18=g4.split(",");
			String[] str19=g5.split(",");
			String[] str20=g6.split(",");
			String[] str21=hy.split(",");
			String[] str22=chuku.split(",");
			if(str1.length==str15.length){
				
			}else{
			try {
					throw new ZdyException("消费大类表数据和现场咨询表数据不匹配");
				} catch (ZdyException e) {
					localtransactionManager.rollback(status);
					String str =e.getMessage();	
					if(str.indexOf("不匹配")>0){
						map.put("data", "102");
						return  map;
					}
				}
				
			}
		if(str1.length>1){
			for(int i=0;i<str1.length;i++){
				BillSub bs =new BillSub();
				bs.setConsumeclass(str1[i]);
				bs.setProject(str2[i]);					
				bs.setCropid(cropid);
	
				if(str3[i]==""||str3[i]=="null"||str3[i]==null||str3[i].equals("1")){
					bs.setSubinfo("");
				}else{
					bs.setSubinfo(str3[i]);
				}
				
				
			
				if(str4[i]==""||str4[i]=="null"||str4[i]==null||str4[i].equals("1")){
					bs.setOperationDoctor("");
				}else{
				bs.setOperationDoctor(str4[i]);
				}
				
				
				
				if(str5[i]==""||str5[i]=="null"||str5[i]==null||str5[i].equals("1")){
					bs.setSecondDoctor("");
				}else{
					bs.setSecondDoctor(str5[i]);
				}
				
				
				
				
				if(str6[i]==""||str6[i]=="null"||str6[i]==null||str6[i].equals("1")){
					bs.setUnoperationDoctor("");
				}else{
					bs.setUnoperationDoctor(str6[i]);
				}
				
				
				if(str7[i]==""||str7[i]=="null"||str7[i]==null||str7[i].equals("1")){
					bs.setAssistantDictor("");
				}else{
					bs.setAssistantDictor(str7[i]);
				}
				
				
				bs.setPrice(str8[i]);
				bs.setQuantity(str9[i]);
				
				bs.setSjje(Integer.parseInt(str8[i])*Integer.parseInt(str9[i])+"");
				
				
				if(str10[i]==""||str10[i]=="null"||str10[i]==null||str10[i].equals("1")){
					bs.setDiscount("");
				}else{
					bs.setDiscount(str10[i]);
				}
				

				
				if(str11[i]==""||str11[i]=="null"||str11[i]==null||str11[i].equals("1")){
					bs.setPriceAfterDiscount("");
				}else{
					bs.setPriceAfterDiscount(str11[i]);	
				}
				
				
				
				
				if(str12[i]==""||str12[i]=="null"||str12[i]==null||str12[i].equals("1")){
					bs.setRemark("");
				}else{
					bs.setRemark(str12[i]);		
				}
				
				if(str13[i]==""||str13[i]=="null"||str13[i]==null||str13[i].equals("1")){
					bs.setAmount("");
				}else{
					bs.setAmount(str13[i]);	
				}
				
				if(str14[i]==""||str14[i]=="null"||str14[i]==null||str14[i].equals("1")){
					bs.setFssbz("");
				}else{
					bs.setFssbz(str14[i]);
				}
				
				if(str15[i]==""||str15[i]=="null"||str15[i]==null||str15[i].equals("1")){
					bs.setXczx("");
				}else{
					bs.setXczx(str15[i]);
				}
				
				if(str16[i]==""||str16[i]=="null"||str16[i]==null||str16[i].equals("1")){
					bs.setPhonezx("");
				}else{
					bs.setPhonezx(str16[i]);
				}
				
				if(str17[i]==""||str17[i]=="null"||str17[i]==null||str17[i].equals("1")){
					bs.setWebzx("");
				}else{
					bs.setWebzx(str17[i]);
				}
				
				if(str18[i]==""||str18[i]=="null"||str18[i]==null||str18[i].equals("1")){
					bs.setScb("");
				}else{
					bs.setScb(str18[i]);
				}
				
				if(str19[i]==""||str19[i]=="null"||str19[i]==null||str19[i].equals("1")){
					bs.setMenzhen("");
				}else{
					bs.setMenzhen(str19[i]);
				}
				
				if(str20[i]==""||str20[i]=="null"||str20[i]==null||str20[i].equals("1")){
					bs.setOtherpp("");
				}else{
					bs.setOtherpp(str20[i]);
				}
				
				if(str21[i]==""||str21[i]=="null"||str21[i]==null||str21[i].equals("1")){
					bs.setHydw("");
				}else{
					bs.setHydw(str21[i]);
				}
				
				if(str22[i]==""||str22[i]=="null"||str22[i]==null||str22[i].equals("1")){
					bs.setChuku("");
				}else{
					bs.setChuku(str22[i]);
				}
				
				
				
				bs.setSerialno(lsh);
				bs.setZhuangtai("0");
				listbs.add(bs);
				}
			
			}else{
				BillSub bs =new BillSub();
				bs.setConsumeclass(str1[0]);
				bs.setProject(str2[0]);
				bs.setCropid(cropid);
				
				
				if(str3[0]==""||str3[0]=="null"||str3[0]==null||str3[0].equals("1")){
					bs.setSubinfo("");
				}else{
					bs.setSubinfo(str3[0]);
				}
				
				
				if(str4[0]==""||str4[0]=="null"||str4[0]==null||str4[0].equals("1")){
					bs.setOperationDoctor("");
				}else{
				bs.setOperationDoctor(str4[0]);
				}
				
				
				if(str5[0]==""||str5[0]=="null"||str5[0]==null||str5[0].equals("1")){
					bs.setSecondDoctor("");
				}else{
					bs.setSecondDoctor(str5[0]);
				}
			
				
			
				if(str6[0]==""||str6[0]=="null"||str6[0]==null||str6[0].equals("1")){
					bs.setUnoperationDoctor("");
				}else{
					bs.setUnoperationDoctor(str6[0]);
				}
				
				
				
				if(str7[0]==""||str7[0]=="null"||str7[0]==null||str7[0].equals("1")){
					bs.setAssistantDictor("");
				}else{
					bs.setAssistantDictor(str7[0]);
				}
		
					
				bs.setPrice(str8[0]);
				bs.setCropid(cropid);
				bs.setQuantity(str9[0]);
				
				bs.setSjje(Integer.parseInt(str8[0])*Integer.parseInt(str9[0])+"");
				
				if(str10[0]==""||str10[0]=="null"||str10[0]==null||str10[0].equals("1")){
					bs.setDiscount("");
				}else{
					bs.setDiscount(str10[0]);
				}
		
				
				
				
				if(str11[0]==""||str11[0]=="null"||str11[0]==null||str11[0].equals("1")){
					bs.setPriceAfterDiscount("");
				}else{
					bs.setPriceAfterDiscount(str11[0]);	
				}
				
				
				
				
				if(str12[0]==""||str12[0]=="null"||str12[0]==null||str12[0].equals("1")){
					bs.setRemark("");
				}else{
					bs.setRemark(str12[0]);		
				}
				if(str13[0]==""||str13[0]=="null"||str13[0]==null||str13[0].equals("1")){
					bs.setAmount("");
				}else{
					bs.setAmount(str13[0]);	
				}
				if(str14[0]==""||str14[0]=="null"||str14[0]==null||str14[0].equals("1")){
					bs.setFssbz("");
				}else{
					bs.setFssbz(str14[0]);
				}
				if(str15[0]==""||str15[0]=="null"||str15[0]==null||str15[0].equals("1")){
					bs.setXczx("");
				}else{
					bs.setXczx(str15[0]);
				}
				
				if(str16[0]==""||str16[0]=="null"||str16[0]==null||str16[0].equals("1")){
					bs.setPhonezx("");
				}else{
					bs.setPhonezx(str16[0]);
				}
				
				if(str17[0]==""||str17[0]=="null"||str17[0]==null||str17[0].equals("1")){
					bs.setWebzx("");
				}else{
					bs.setWebzx(str17[0]);
				}
				
				if(str18[0]==""||str18[0]=="null"||str18[0]==null||str18[0].equals("1")){
					bs.setScb("");
				}else{
					bs.setScb(str18[0]);
				}
				
				if(str19[0]==""||str19[0]=="null"||str19[0]==null||str19[0].equals("1")){
					bs.setMenzhen("");
				}else{
					bs.setMenzhen(str19[0]);
				}
				
				if(str20[0]==""||str20[0]=="null"||str20[0]==null||str20[0].equals("1")){
					bs.setOtherpp("");
				}else{
					bs.setOtherpp(str20[0]);
				}
				
				if(str21[0]==""||str21[0]=="null"||str21[0]==null||str21[0].equals("1")){
					bs.setHydw("");
				}else{
					bs.setHydw(str21[0]);
				}
				
				if(str22[0]==""||str22[0]=="null"||str22[0]==null||str22[0].equals("1")){
					bs.setChuku("");
				}else{
					bs.setChuku(str22[0]);
				}
				
				
				
				bs.setSerialno(lsh);
				bs.setZhuangtai("0");
				listbs.add(bs);
			}
		
		
//===========================================================================================
			//结算方式
	 
		String aa = new String(g31.getBytes("ISO8859-1"),"UTF-8");
		
		
			String[] str31 = aa.split(",");
			
			if(aa.equals("1,")){
				
			}else{
				
			String[] str32 = g32.split(",");
			String[] str33 = g33.split(",");
			String[] str34 = g34.split(",");
			if(str31.length>1){
				for(int i=0;i<str31.length;i++){
			
				Settlestyle  sl = ss.selectbys(str31[i]);
				
				sl.setSettlement(str31[i]);
				

				if(str32[i]==""||str32[i]=="null"||str32[i]==null||str32[i].equals("1")){
					sl.setMingxi("");
				}else{
					sl.setMingxi(str32[i]);	
				}

				sl.setAmount(str33[i]);
				
				

				if(str34[i]==""||str34[i]=="null"||str34[i]==null||str34[i].equals("1")){
					sl.setTips("");
				}else{
					sl.setTips(str34[i]);
				}
				
				
				sl.setIsno(lsh);
				sl.setCropid(cropid);
				sl.setZhuangtai("0");
				
				if(aa.equals("1,")){
					
				}else{
					int a=0;
					a = ss.insert(sl);
					if(a==0){
						break;
					}	
			}
				
			
				}
			}else{
				Settlestyle  sl = ss.selectbys(str31[0]);
				sl.setSettlement(str31[0]);
				if(str32[0]==""||str32[0]=="null"||str32[0]==null||str32[0].equals("1")){
					sl.setMingxi("");
				}else{
					sl.setMingxi(str32[0]);	
				}
				sl.setAmount(str33[0]);


				if(str34[0]==""||str34[0]=="null"||str34[0]==null||str34[0].equals("1")){
					sl.setTips("");
				}else{
					sl.setTips(str34[0]);
				}
				sl.setIsno(lsh);
				sl.setCropid(cropid);
				sl.setZhuangtai("0");
				
			if(aa.equals("1,")){
					
				}else{
					int a=0;
					a = ss.insert(sl);
					
				}
				
			}
			
			}
			List<ReceivepayManger> listrm = new ArrayList<ReceivepayManger>();
			if(g41.equals("1,")){
				
			}else{
			String[] str41 = g41.split(",");		
			String[] str42 = g42.split(",");
			String[] str43 = g43.split(",");
			
			if(str41.length>1){
				for(int i=0;i<str41.length;i++){
					
					int type=0;
					if(str41[i].equals("应收")){
						type=1;
					}
					if(str41[i].equals("应付")){
						type=0;
					}
				ReceivepayManger rm =lrs.selectby(type,str42[i]);
				
					rm.setType(type);
					rm.setCorp(str42[i]);
					rm.setAmount(str43[i]);
					rm.setIsno(lsh);
					rm.setCorpid(cropid);
					rm.setZhuangtai("0");
					listrm.add(rm);
				}
			}else{
				int type=0;
				if(str41[0].equals("应收")){
					type=1;
				}
				if(str41[0].equals("应付")){
					type=0;
				}
			ReceivepayManger rm =lrs.selectby(type,str42[0]);
				rm.setType(type);
				rm.setAmount(str43[0]);
				rm.setIsno(lsh);	
				rm.setCorpid(cropid);
				rm.setZhuangtai("0");
				listrm.add(rm);
			}
		}
			 int p = 0;
			 int a =0;
			 int l =0;
		
			
		

			for(int j =0;j<listbs.size();j++){
				p=	billser.insertBs(listbs.get(j));
				if(p==0){
					break;
				}
			} 
			 

			//System.out.println("==========================================================");
	
			//System.out.println("==========================================================");
		if(g41.equals("1,")){
			
		}else{
			for(int z =0;z<listrm.size();z++){
				ReceivepayManger rm = listrm.get(z);
				System.out.println(rm.toString());
				l = lrs.insertRp(listrm.get(z));
				if(l==0){
					break;
				}
			}
		}	
			
			
			map.put("data", "插入成功");
		
			localtransactionManager.commit(status);
		} catch (Exception e) {
			// TODO: handle exception
			localtransactionManager.rollback(status);
			if(e.getMessage().indexOf("Duplicate entry '"+lsh+"' for key 2")>0){
				map.put("data", "101");
			}
			
			return map;
		
		}
		return map;
	}
	
	
	
	
	
	@RequestMapping(value="/update/billmain")
	@ResponseBody
	public Object updateBillmain(HttpServletRequest request,String lsh,String cropid,String dd,String danju,String fph,String name,String phone,
			String banka,String youhui,String yuyue,String fptt,String g1,String g2,String g3,String g4,String g5,String g6,String hy,String chuku,String g21,String g22,String g23,String g24,String g25,String g26,String g27,String g28,String g29,String g210,String g211,String g212,String g213,String g214,String g31,String g32,String g33,String g34,String g41,String g42,String g43,String g20,String g30,String g40){
		
	
		
		TransactionStatus status = localtransactionManager.getTransaction(def);
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
		def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
 		Map<String,Object>  map =  new HashMap<String,Object>();
		HttpSession session  = request.getSession();
	
		
	
		
		String shoukuanren =(String)session.getAttribute("name");

		
		try {
			CropDTD c = new CropDTD();
			c.setCorpid(cropid);
			c.setIsno(lsh);
			String zhuangtai=billmainser.selectBMType(c);
			String shzhuangtai=billmainser.selectBMshType(c);
			if(zhuangtai.equals("1")&&shzhuangtai.equals("0")){
				 map.put("data", "2");
				 return map;
			}else if(zhuangtai.equals("0")&&shzhuangtai.equals("1")){
				map.put("data", "3");
				return map;
			}else if(zhuangtai.equals("1")&&shzhuangtai.equals("1")){
				map.put("data", "4");
				return map;
			}
			else{
			
			BillMain  b = new BillMain();
			b.setDate(dd);
			if(danju==""||danju=="null"||danju==null){
				b.setNo("");
			}else{
				b.setNo(danju);
			}
			if(lsh==""||lsh=="null"||lsh==null){
				b.setSerialno("");
			}else{
				b.setSerialno(lsh);
			}
			if(fph==""||fph=="null"||fph==null){
				b.setInvoiceno("");
			}else{
				b.setInvoiceno(fph);
			}
			b.setCustomer(name);
			if(phone==""||phone=="null"||phone==null){
				b.setTelno("");
			}else{
				b.setTelno(phone);
			}
			if(banka==""||banka=="null"||banka==null){
				b.setCardtime("");
			}else{
				b.setCardtime(banka);
			}
			if(youhui==""||youhui=="null"||youhui==null){
				b.setBillmaincol3("");
			}else{
				b.setBillmaincol3(youhui);
			}
	
			if(yuyue==""||yuyue=="null"||yuyue==null){
				b.setReservatime("");
			}else{
				b.setReservatime(yuyue);
			}
		/*	if(chuku==""||chuku=="null"||chuku==null){
				b.setOutboundorder("");
			}else{
				b.setOutboundorder(chuku);
			}*/
			if(fptt==""||fptt=="null"||fptt==null){
				b.setInvoicehead("");
			}else{
				b.setInvoicehead(fptt);
			}
			
			b.setCropid(cropid);
			b.setZhuangtai("0");
			b.setShoukuanren(shoukuanren);
	       int o = billmainser.updateOb(b);
			
	    //子表   
	       List<BillSub> listbs = new ArrayList<BillSub>();
		
	       if(g20.indexOf("undefined")>=0){
	    	   
				String[] str0=g20.split(",");
				String[] str1=g21.split(",");
				String[] str2=g22.split(",");
				String[] str3=g23.split(",");
				String[] str4=g24.split(",");
				String[] str5=g25.split(",");
				String[] str6=g26.split(",");
				String[] str7=g27.split(",");
				String[] str8=g28.split(",");
				String[] str9=g29.split(",");
				String[] str10=g210.split(",");
				String[] str11=g211.split(",");
				String[] str12=g212.split(",");
				String[] str13=g213.split(",");
				String[] str14=g214.split(",");
				
				
				
				String[] str15=g1.split(",");
				String[] str16=g2.split(",");
				String[] str17=g3.split(",");
				String[] str18=g4.split(",");
				String[] str19=g5.split(",");
				String[] str20=g6.split(",");
				String[] str21=hy.split(",");
				String[] str22=chuku.split(",");
				
			if(str1.length>1){
				for(int i=0;i<str1.length;i++){
					
					if(str0[i].equals("undefined")){
						
						BillSub bs =new BillSub();
						bs.setConsumeclass(str1[i]);
						bs.setProject(str2[i]);					
						bs.setCropid(cropid);
			
						if(str3[i]==""||str3[i]=="null"||str3[i]==null||str3[i].equals("1")){
							bs.setSubinfo("");
						}else{
							bs.setSubinfo(str3[i]);
						}

						if(str4[i]==""||str4[i]=="null"||str4[i]==null||str4[i].equals("1")){
							bs.setOperationDoctor("");
						}else{
						bs.setOperationDoctor(str4[i]);
						}
						
						
						
						if(str5[i]==""||str5[i]=="null"||str5[i]==null||str5[i].equals("1")){
							bs.setSecondDoctor("");
						}else{
							bs.setSecondDoctor(str5[i]);
						}
						
						
						
						
						if(str6[i]==""||str6[i]=="null"||str6[i]==null||str6[i].equals("1")){
							bs.setUnoperationDoctor("");
						}else{
							bs.setUnoperationDoctor(str6[i]);
						}
						
						
						if(str7[i]==""||str7[i]=="null"||str7[i]==null||str7[i].equals("1")){
							bs.setAssistantDictor("");
						}else{
							bs.setAssistantDictor(str7[i]);
						}
						
						
						bs.setPrice(str8[i]);
						bs.setQuantity(str9[i]);
						
						bs.setSjje(Integer.parseInt(str8[i])*Integer.parseInt(str9[i])+"");
						
						
						if(str10[i]==""||str10[i]=="null"||str10[i]==null||str10[i].equals("1")){
							bs.setDiscount("");
						}else{
							bs.setDiscount(str10[i]);
						}
						

						
						if(str11[i]==""||str11[i]=="null"||str11[i]==null||str11[i].equals("1")){
							bs.setPriceAfterDiscount("");
						}else{
							bs.setPriceAfterDiscount(str11[i]);	
						}
						
						
						
						
						if(str12[i]==""||str12[i]=="null"||str12[i]==null||str12[i].equals("1")){
							bs.setRemark("");
						}else{
							bs.setRemark(str12[i]);		
						}
						
						if(str13[i]==""||str13[i]=="null"||str13[i]==null||str13[i].equals("1")){
							bs.setAmount("");
						}else{
							bs.setAmount(str13[i]);	
						}
						
						if(str14[i]==""||str14[i]=="null"||str14[i]==null||str14[i].equals("1")){
							bs.setFssbz("");
						}else{
							bs.setFssbz(str14[i]);
						}
						
						if(str15[i]==""||str15[i]=="null"||str15[i]==null||str15[i].equals("1")){
							bs.setXczx("");
						}else{
							bs.setXczx(str15[i]);
						}
						
						if(str16[i]==""||str16[i]=="null"||str16[i]==null||str16[i].equals("1")){
							bs.setPhonezx("");
						}else{
							bs.setPhonezx(str16[i]);
						}
						
						if(str17[i]==""||str17[i]=="null"||str17[i]==null||str17[i].equals("1")){
							bs.setWebzx("");
						}else{
							bs.setWebzx(str17[i]);
						}
						
						if(str18[i]==""||str18[i]=="null"||str18[i]==null||str18[i].equals("1")){
							bs.setScb("");
						}else{
							bs.setScb(str18[i]);
						}
						
						if(str19[i]==""||str19[i]=="null"||str19[i]==null||str19[i].equals("1")){
							bs.setMenzhen("");
						}else{
							bs.setMenzhen(str19[i]);
						}
						
						if(str20[i]==""||str20[i]=="null"||str20[i]==null||str20[i].equals("1")){
							bs.setOtherpp("");
						}else{
							bs.setOtherpp(str20[i]);
						}
						
						if(str21[i]==""||str21[i]=="null"||str21[i]==null||str21[i].equals("1")){
							bs.setHydw("");
						}else{
							bs.setHydw(str21[i]);
						}
						
						if(str22[i]==""||str22[i]=="null"||str22[i]==null||str22[i].equals("1")){
							bs.setChuku("");
						}else{
							bs.setChuku(str22[i]);
						}
						
						bs.setSerialno(lsh);
						bs.setZhuangtai("0");
						
						billser.insertBs(bs);
					}else{
					
					BillSub bs =new BillSub();
					bs.setId(Integer.parseInt(str0[i]));
					bs.setConsumeclass(str1[i]);
					bs.setProject(str2[i]);					
					bs.setCropid(cropid);
					
					
					if(str3[i]==""||str3[i]=="null"||str3[i]==null||str3[i].equals("1")){
						bs.setSubinfo("");
					}else{
						bs.setSubinfo(str3[i]);
					}
					
					
				
					if(str4[i]==""||str4[i]=="null"||str4[i]==null||str4[i].equals("1")){
						bs.setOperationDoctor("");
					}else{
					bs.setOperationDoctor(str4[i]);
					}
					
					
					
					if(str5[i]==""||str5[i]=="null"||str5[i]==null||str5[i].equals("1")){
						bs.setSecondDoctor("");
					}else{
						bs.setSecondDoctor(str5[i]);
					}
					
					
					
					
					if(str6[i]==""||str6[i]=="null"||str6[i]==null||str6[i].equals("1")){
						bs.setUnoperationDoctor("");
					}else{
						bs.setUnoperationDoctor(str6[i]);
					}
					
					
					if(str7[i]==""||str7[i]=="null"||str7[i]==null||str7[i].equals("1")){
						bs.setAssistantDictor("");
					}else{
						bs.setAssistantDictor(str7[i]);
					}
					
					
					bs.setPrice(str8[i]);
					bs.setQuantity(str9[i]);
					
				
					
					
					if(str10[i]==""||str10[i]=="null"||str10[i]==null||str10[i].equals("1")){
						bs.setDiscount("");
					}else{
						bs.setDiscount(str10[i]);
					}
					

					
					if(str11[i]==""||str11[i]=="null"||str11[i]==null||str11[i].equals("1")){
						bs.setPriceAfterDiscount("");
					}else{
						bs.setPriceAfterDiscount(str11[i]);	
					}
					
					
					
					
					if(str12[i]==""||str12[i]=="null"||str12[i]==null||str12[i].equals("1")){
						bs.setRemark("");
					}else{
						bs.setRemark(str12[i]);		
					}
					
					if(str13[i]==""||str13[i]=="null"||str13[i]==null||str13[i].equals("1")){
						bs.setAmount("");
					}else{
						bs.setAmount(str13[i]);	
					}
					if(str14[i]==""||str14[i]=="null"||str14[i]==null||str14[i].equals("1")){
						bs.setFssbz("");
					}else{
						bs.setFssbz(str14[i]);
					}
					
					if(str15[i]==""||str15[i]=="null"||str15[i]==null||str15[i].equals("1")){
						bs.setXczx("");
					}else{
						bs.setXczx(str15[i]);
					}
					
					if(str16[i]==""||str16[i]=="null"||str16[i]==null||str16[i].equals("1")){
						bs.setPhonezx("");
					}else{
						bs.setPhonezx(str16[i]);
					}
					
					if(str17[i]==""||str17[i]=="null"||str17[i]==null||str17[i].equals("1")){
						bs.setWebzx("");
					}else{
						bs.setWebzx(str17[i]);
					}
					
					if(str18[i]==""||str18[i]=="null"||str18[i]==null||str18[i].equals("1")){
						bs.setScb("");
					}else{
						bs.setScb(str18[i]);
					}
					
					if(str19[i]==""||str19[i]=="null"||str19[i]==null||str19[i].equals("1")){
						bs.setMenzhen("");
					}else{
						bs.setMenzhen(str19[i]);
					}
					
					if(str20[i]==""||str20[i]=="null"||str20[i]==null||str20[i].equals("1")){
						bs.setOtherpp("");
					}else{
						bs.setOtherpp(str20[i]);
					}
					
					if(str21[i]==""||str21[i]=="null"||str21[i]==null||str21[i].equals("1")){
						bs.setHydw("");
					}else{
						bs.setHydw(str21[i]);
					}
					if(str22[i]==""||str22[i]=="null"||str22[i]==null||str22[i].equals("1")){
						bs.setChuku("");
					}else{
						bs.setChuku(str22[i]);
					}
					
					
					bs.setSerialno(lsh);
					bs.setZhuangtai("0");
					listbs.add(bs);
					}
				 }
				
				}else{
					BillSub bs =new BillSub();
					bs.setId(Integer.parseInt(str0[0]));
					bs.setConsumeclass(str1[0]);
					bs.setProject(str2[0]);
					bs.setCropid(cropid);
					
					
					if(str3[0]==""||str3[0]=="null"||str3[0]==null||str3[0].equals("1")){
						bs.setSubinfo("");
					}else{
						bs.setSubinfo(str3[0]);
					}
					
					
					if(str4[0]==""||str4[0]=="null"||str4[0]==null||str4[0].equals("1")){
						bs.setOperationDoctor("");
					}else{
					bs.setOperationDoctor(str4[0]);
					}
					
					
					if(str5[0]==""||str5[0]=="null"||str5[0]==null||str5[0].equals("1")){
						bs.setSecondDoctor("");
					}else{
						bs.setSecondDoctor(str5[0]);
					}
				
					
				
					if(str6[0]==""||str6[0]=="null"||str6[0]==null||str6[0].equals("1")){
						bs.setUnoperationDoctor("");
					}else{
						bs.setUnoperationDoctor(str6[0]);
					}
					
					
					
					if(str7[0]==""||str7[0]=="null"||str7[0]==null||str7[0].equals("1")){
						bs.setAssistantDictor("");
					}else{
						bs.setAssistantDictor(str7[0]);
					}
			
						
					bs.setPrice(str8[0]);
					bs.setCropid(cropid);
					bs.setQuantity(str9[0]);
					
					
					
					if(str10[0]==""||str10[0]=="null"||str10[0]==null){
						bs.setDiscount("");
					}else{
						bs.setDiscount(str10[0]);
					}
			
					
					
					
					if(str11[0]==""||str11[0]=="null"||str11[0]==null){
						bs.setPriceAfterDiscount("");
					}else{
						bs.setPriceAfterDiscount(str11[0]);	
					}
					
					
					
					
					if(str12[0]==""||str12[0]=="null"||str12[0]==null){
						bs.setRemark("");
					}else{
						bs.setRemark(str12[0]);		
					}
					if(str13[0]==""||str13[0]=="null"||str13[0]==null||str13[0].equals("1")){
						bs.setAmount("");
					}else{
						bs.setAmount(str13[0]);	
					}
					if(str14[0]==""||str14[0]=="null"||str14[0]==null||str14[0].equals("1")){
						bs.setFssbz("");
					}else{
						bs.setFssbz(str14[0]);
					}
					if(str15[0]==""||str15[0]=="null"||str15[0]==null||str15[0].equals("1")){
						bs.setXczx("");
					}else{
						bs.setXczx(str15[0]);
					}
					
					if(str16[0]==""||str16[0]=="null"||str16[0]==null||str16[0].equals("1")){
						bs.setPhonezx("");
					}else{
						bs.setPhonezx(str16[0]);
					}
					
					if(str17[0]==""||str17[0]=="null"||str17[0]==null||str17[0].equals("1")){
						bs.setWebzx("");
					}else{
						bs.setWebzx(str17[0]);
					}
					
					if(str18[0]==""||str18[0]=="null"||str18[0]==null||str18[0].equals("1")){
						bs.setScb("");
					}else{
						bs.setScb(str18[0]);
					}
					
					if(str19[0]==""||str19[0]=="null"||str19[0]==null||str19[0].equals("1")){
						bs.setMenzhen("");
					}else{
						bs.setMenzhen(str19[0]);
					}
					
					if(str20[0]==""||str20[0]=="null"||str20[0]==null||str20[0].equals("1")){
						bs.setOtherpp("");
					}else{
						bs.setOtherpp(str20[0]);
					}
					
					if(str21[0]==""||str21[0]=="null"||str21[0]==null||str21[0].equals("1")){
						bs.setHydw("");
					}else{
						bs.setHydw(str21[0]);
					}
					
					if(str22[0]==""||str22[0]=="null"||str22[0]==null||str22[0].equals("1")){
						bs.setChuku("");
					}else{
						bs.setChuku(str22[0]);
					}
						
					bs.setSerialno(lsh);
					bs.setZhuangtai("0");
					listbs.add(bs);
				
			}
	       }else{
	       
			String[] str0=g20.split(",");
			String[] str1=g21.split(",");
			String[] str2=g22.split(",");
			String[] str3=g23.split(",");
			String[] str4=g24.split(",");
			String[] str5=g25.split(",");
			String[] str6=g26.split(",");
			String[] str7=g27.split(",");
			String[] str8=g28.split(",");
			String[] str9=g29.split(",");
			String[] str10=g210.split(",");
			String[] str11=g211.split(",");
			String[] str12=g212.split(",");
			String[] str13=g213.split(",");
			String[] str14=g214.split(",");
			
			
			
			String[] str15=g1.split(",");
			String[] str16=g2.split(",");
			String[] str17=g3.split(",");
			String[] str18=g4.split(",");
			String[] str19=g5.split(",");
			String[] str20=g6.split(",");
			String[] str21=hy.split(",");
			String[] str22=chuku.split(",");
			
		if(str1.length>1){
			for(int i=0;i<str1.length;i++){
				BillSub bs =new BillSub();
				bs.setId(Integer.parseInt(str0[i]));
				bs.setConsumeclass(str1[i]);
				bs.setProject(str2[i]);					
				bs.setCropid(cropid);
				
				
				if(str3[i]==""||str3[i]=="null"||str3[i]==null||str3[i].equals("1")){
					bs.setSubinfo("");
				}else{
					bs.setSubinfo(str3[i]);
				}
				
				
			
				if(str4[i]==""||str4[i]=="null"||str4[i]==null||str4[i].equals("1")){
					bs.setOperationDoctor("");
				}else{
				bs.setOperationDoctor(str4[i]);
				}
				
				
				
				if(str5[i]==""||str5[i]=="null"||str5[i]==null||str5[i].equals("1")){
					bs.setSecondDoctor("");
				}else{
					bs.setSecondDoctor(str5[i]);
				}
				
				
				
				
				if(str6[i]==""||str6[i]=="null"||str6[i]==null||str6[i].equals("1")){
					bs.setUnoperationDoctor("");
				}else{
					bs.setUnoperationDoctor(str6[i]);
				}
				
				
				if(str7[i]==""||str7[i]=="null"||str7[i]==null||str7[i].equals("1")){
					bs.setAssistantDictor("");
				}else{
					bs.setAssistantDictor(str7[i]);
				}
				
				
				bs.setPrice(str8[i]);
				bs.setQuantity(str9[i]);
				
			
				
				
				if(str10[i]==""||str10[i]=="null"||str10[i]==null||str10[i].equals("1")){
					bs.setDiscount("");
				}else{
					bs.setDiscount(str10[i]);
				}
				

				
				if(str11[i]==""||str11[i]=="null"||str11[i]==null||str11[i].equals("1")){
					bs.setPriceAfterDiscount("");
				}else{
					bs.setPriceAfterDiscount(str11[i]);	
				}
				
				
				
				
				if(str12[i]==""||str12[i]=="null"||str12[i]==null||str12[i].equals("1")){
					bs.setRemark("");
				}else{
					bs.setRemark(str12[i]);		
				}
				
				if(str13[i]==""||str13[i]=="null"||str13[i]==null||str13[i].equals("1")){
					bs.setAmount("");
				}else{
					bs.setAmount(str13[i]);	
				}
				if(str14[i]==""||str14[i]=="null"||str14[i]==null||str14[i].equals("1")){
					bs.setFssbz("");
				}else{
					bs.setFssbz(str14[i]);
				}
				
				if(str15[i]==""||str15[i]=="null"||str15[i]==null||str15[i].equals("1")){
					bs.setXczx("");
				}else{
					bs.setXczx(str15[i]);
				}
				
				if(str16[i]==""||str16[i]=="null"||str16[i]==null||str16[i].equals("1")){
					bs.setPhonezx("");
				}else{
					bs.setPhonezx(str16[i]);
				}
				
				if(str17[i]==""||str17[i]=="null"||str17[i]==null||str17[i].equals("1")){
					bs.setWebzx("");
				}else{
					bs.setWebzx(str17[i]);
				}
				
				if(str18[i]==""||str18[i]=="null"||str18[i]==null||str18[i].equals("1")){
					bs.setScb("");
				}else{
					bs.setScb(str18[i]);
				}
				
				if(str19[i]==""||str19[i]=="null"||str19[i]==null||str19[i].equals("1")){
					bs.setMenzhen("");
				}else{
					bs.setMenzhen(str19[i]);
				}
				
				if(str20[i]==""||str20[i]=="null"||str20[i]==null||str20[i].equals("1")){
					bs.setOtherpp("");
				}else{
					bs.setOtherpp(str20[i]);
				}
				
				if(str21[i]==""||str21[i]=="null"||str21[i]==null||str21[i].equals("1")){
					bs.setHydw("");
				}else{
					bs.setHydw(str21[i]);
				}
				
				if(str22[i]==""||str22[i]=="null"||str22[i]==null||str22[i].equals("1")){
					bs.setChuku("");
				}else{
					bs.setChuku(str22[i]);
				}
				
				bs.setSerialno(lsh);
				bs.setZhuangtai("0");
				listbs.add(bs);
				}
			
			}else{
				BillSub bs =new BillSub();
				bs.setId(Integer.parseInt(str0[0]));
				bs.setConsumeclass(str1[0]);
				bs.setProject(str2[0]);
				bs.setCropid(cropid);
				
				
				if(str3[0]==""||str3[0]=="null"||str3[0]==null||str3[0].equals("1")){
					bs.setSubinfo("");
				}else{
					bs.setSubinfo(str3[0]);
				}
				
				
				if(str4[0]==""||str4[0]=="null"||str4[0]==null||str4[0].equals("1")){
					bs.setOperationDoctor("");
				}else{
				bs.setOperationDoctor(str4[0]);
				}
				
				
				if(str5[0]==""||str5[0]=="null"||str5[0]==null||str5[0].equals("1")){
					bs.setSecondDoctor("");
				}else{
					bs.setSecondDoctor(str5[0]);
				}
			
				
			
				if(str6[0]==""||str6[0]=="null"||str6[0]==null||str6[0].equals("1")){
					bs.setUnoperationDoctor("");
				}else{
					bs.setUnoperationDoctor(str6[0]);
				}
				
				
				
				if(str7[0]==""||str7[0]=="null"||str7[0]==null||str7[0].equals("1")){
					bs.setAssistantDictor("");
				}else{
					bs.setAssistantDictor(str7[0]);
				}
		
					
				bs.setPrice(str8[0]);
				bs.setCropid(cropid);
				bs.setQuantity(str9[0]);
				
				
				
				if(str10[0]==""||str10[0]=="null"||str10[0]==null){
					bs.setDiscount("");
				}else{
					bs.setDiscount(str10[0]);
				}
		
				
				
				
				if(str11[0]==""||str11[0]=="null"||str11[0]==null){
					bs.setPriceAfterDiscount("");
				}else{
					bs.setPriceAfterDiscount(str11[0]);	
				}
				
				
				
				
				if(str12[0]==""||str12[0]=="null"||str12[0]==null){
					bs.setRemark("");
				}else{
					bs.setRemark(str12[0]);		
				}
				if(str13[0]==""||str13[0]=="null"||str13[0]==null||str13[0].equals("1")){
					bs.setAmount("");
				}else{
					bs.setAmount(str13[0]);	
				}
				if(str14[0]==""||str14[0]=="null"||str14[0]==null||str14[0].equals("1")){
					bs.setFssbz("");
				}else{
					bs.setFssbz(str14[0]);
				}
				if(str15[0]==""||str15[0]=="null"||str15[0]==null||str15[0].equals("1")){
					bs.setXczx("");
				}else{
					bs.setXczx(str15[0]);
				}
				
				if(str16[0]==""||str16[0]=="null"||str16[0]==null||str16[0].equals("1")){
					bs.setPhonezx("");
				}else{
					bs.setPhonezx(str16[0]);
				}
				
				if(str17[0]==""||str17[0]=="null"||str17[0]==null||str17[0].equals("1")){
					bs.setWebzx("");
				}else{
					bs.setWebzx(str17[0]);
				}
				
				if(str18[0]==""||str18[0]=="null"||str18[0]==null||str18[0].equals("1")){
					bs.setScb("");
				}else{
					bs.setScb(str18[0]);
				}
				
				if(str19[0]==""||str19[0]=="null"||str19[0]==null||str19[0].equals("1")){
					bs.setMenzhen("");
				}else{
					bs.setMenzhen(str19[0]);
				}
				
				if(str20[0]==""||str20[0]=="null"||str20[0]==null||str20[0].equals("1")){
					bs.setOtherpp("");
				}else{
					bs.setOtherpp(str20[0]);
				}
				
				if(str21[0]==""||str21[0]=="null"||str21[0]==null||str21[0].equals("1")){
					bs.setHydw("");
				}else{
					bs.setHydw(str21[0]);
				}
				if(str22[0]==""||str22[0]=="null"||str22[0]==null||str22[0].equals("1")){
					bs.setChuku("");
				}else{
					bs.setChuku(str22[0]);
				}
				
					
				bs.setSerialno(lsh);
				bs.setZhuangtai("0");
				listbs.add(bs);
			
		}
	       }	
		
//===========================================================================================
			//结算方式
	       
	       
	   	String aa = new String(g31.getBytes("ISO8859-1"),"UTF-8");
		
		System.out.println(aa+"@@");
		
	       
			List<Settlestyle> listsl =new ArrayList<Settlestyle>();
			String[] str31 = aa.split(",");
			if(aa.equals("1,")){
				
			}else{
				if(g30.indexOf("undefined")>=0){
					
					String[] str30 = g30.split(",");
					String[] str32 = g32.split(",");
					String[] str33 = g33.split(",");
					String[] str34 = g34.split(",");
					
					if(str31.length>1){
						for(int i=0;i<str31.length;i++){
							
							if(str30[i].equals("undefined")){
							
								Settlestyle  sl = ss.selectbys(str31[i]);
										
								sl.setSettlement(str31[i]);
								
								if(str32[i]==""||str32[i]=="null"||str32[i]==null||str32[i].equals("1")){
									sl.setMingxi("");
								}else{
									sl.setMingxi(str32[i]);	
								}
								
								sl.setAmount(str33[i]);
								
								if(str34[i]==""||str34[i]=="null"||str34[i]==null||str34[i].equals("1")){
									sl.setTips("");
								}else{
									sl.setTips(str34[i]);
								}
								sl.setIsno(lsh);
								sl.setCropid(cropid);
								sl.setZhuangtai("0");
								 ss.insert(sl);
							}else{
							updateDTD up= new updateDTD();
							up.setIsno(lsh);
							up.setId(Integer.parseInt(str30[i]));
							Settlestyle  sl = ss.selectby(up);
						sl.setSettlement(str31[i]);
						sl.setId(Integer.parseInt(str30[i]));

						if(str32[i]==""||str32[i]=="null"||str32[i]==null||str32[i].equals("1")){
							sl.setMingxi("");
						}else{
							sl.setMingxi(str32[i]);	
						}

						sl.setAmount(str33[i]);
						
						

						if(str34[i]==""||str34[i]=="null"||str34[i]==null||str34[i].equals("1")){
							sl.setTips("");
						}else{
							sl.setTips(str34[i]);
						}
						
						
						sl.setIsno(lsh);
						sl.setCropid(cropid);
						sl.setZhuangtai("0");
						listsl.add(sl);
						}
						}
					}else{
						updateDTD up= new updateDTD();
						up.setIsno(lsh);
						up.setId(Integer.parseInt(str30[0]));
						Settlestyle  sl = ss.selectby(up);
						sl.setSettlement(str31[0]);
						sl.setId(Integer.parseInt(str30[0]));
						if(str32[0]==""||str32[0]=="null"||str32[0]==null||str32[0].equals("1")){
							sl.setMingxi("");
						}else{
							sl.setMingxi(str32[0]);	
						}
						sl.setAmount(str33[0]);


						if(str34[0]==""||str34[0]=="null"||str34[0]==null||str34[0].equals("1")){
							sl.setTips("");
						}else{
							sl.setTips(str34[0]);
						}
						sl.setIsno(lsh);
						sl.setCropid(cropid);
						sl.setZhuangtai("0");
						listsl.add(sl);
						}
					
					
				}else{
				
			String[] str30 = g30.split(",");
			String[] str32 = g32.split(",");
			String[] str33 = g33.split(",");
			String[] str34 = g34.split(",");
			
			if(str31.length>1){
				for(int i=0;i<str31.length;i++){
					updateDTD up= new updateDTD();
					up.setIsno(lsh);
					up.setId(Integer.parseInt(str30[i]));
					Settlestyle  sl = ss.selectby(up);
					sl.setSettlement(str31[i]);
					sl.setId(Integer.parseInt(str30[i]));

				if(str32[i]==""||str32[i]=="null"||str32[i]==null||str32[i].equals("1")){
					sl.setMingxi("");
				}else{
					sl.setMingxi(str32[i]);	
				}

				sl.setAmount(str33[i]);
				
				

				if(str34[i]==""||str34[i]=="null"||str34[i]==null||str34[i].equals("1")){
					sl.setTips("");
				}else{
					sl.setTips(str34[i]);
				}
				
				
				sl.setIsno(lsh);
				sl.setCropid(cropid);
				sl.setZhuangtai("0");
				listsl.add(sl);
				}
			}else{
				updateDTD up= new updateDTD();
				up.setIsno(lsh);
				up.setId(Integer.parseInt(str30[0]));
				Settlestyle  sl = ss.selectby(up);
				sl.setSettlement(str31[0]);
				sl.setId(Integer.parseInt(str30[0]));
				if(str32[0]==""||str32[0]=="null"||str32[0]==null||str32[0].equals("1")){
					sl.setMingxi("");
				}else{
					sl.setMingxi(str32[0]);	
				}
				sl.setAmount(str33[0]);


				if(str34[0]==""||str34[0]=="null"||str34[0]==null||str34[0].equals("1")){
					sl.setTips("");
				}else{
					sl.setTips(str34[0]);
				}
				sl.setIsno(lsh);
				sl.setCropid(cropid);
				sl.setZhuangtai("0");
				listsl.add(sl);
				}
			}
			}
			
			
			
			List<ReceivepayManger> listrm = new ArrayList<ReceivepayManger>();
			
			if(g41.equals("1,")){
				
			}else{
				if(g40.indexOf("undefined")>=0){
					
					String[] str40 = g40.split(",");
					String[] str41 = g41.split(",");		
					String[] str42 = g42.split(",");
					String[] str43 = g43.split(",");
					
					if(str41.length>1){
						
						for(int i=0;i<str41.length;i++){
							
							if(str40[i].equals("undefined")){
								
								int type=0;
								if(str41[i].equals("应收")){
									type=1;
								}
								if(str41[i].equals("应付")){
									type=0;
								}
												
								ReceivepayManger rm =lrs.selectby(type,str42[i]);
								
								rm.setType(type);
								rm.setCorp(str42[i]);
								rm.setAmount(str43[i]);
								rm.setIsno(lsh);
								rm.setCorpid(cropid);
								rm.setZhuangtai("0");
								lrs.insertRp(rm);
							}else{
									
								int type=0;
								if(str41[i].equals("应收")){
									type=1;
								}
								if(str41[i].equals("应付")){
									type=0;
								}
								
							
							RmDTD rmd =  lrs.selectby2(type, str42[i]);
								
							ReceivepayManger rm = new ReceivepayManger();
							
								rm.setId(Integer.parseInt(str40[i]));
								rm.setSubjectcode(rmd.getSubjectcode());
								rm.setSubjectname(rmd.getSubjectname());
								rm.setRemark(rmd.getRemark());
								rm.setType(type);
								rm.setCorp(str42[i]);
								rm.setAmount(str43[i]);
								rm.setIsno(lsh);
								rm.setCorpid(cropid);
								rm.setZhuangtai("0");
								listrm.add(rm);
							}
			
							
						}
					}else{
						int type=0;
						if(str41[0].equals("应收")){
							type=1;
						}
						if(str41[0].equals("应付")){
							type=0;
						}
						RmDTD rmd =  lrs.selectby2(type, str42[0]);
						
						ReceivepayManger rm = new ReceivepayManger();
						
							rm.setId(Integer.parseInt(str40[0]));
							rm.setSubjectcode(rmd.getSubjectcode());
							rm.setSubjectname(rmd.getSubjectname());
							rm.setRemark(rmd.getRemark());
							rm.setType(type);
							rm.setCorp(str42[0]);
							rm.setAmount(str43[0]);
							rm.setIsno(lsh);
							rm.setCorpid(cropid);
							rm.setZhuangtai("0");
							listrm.add(rm);
					}
					
					
				}else{
					String[] str40 = g40.split(",");
					String[] str41 = g41.split(",");		
					String[] str42 = g42.split(",");
					String[] str43 = g43.split(",");
					
					if(str41.length>1){
						for(int i=0;i<str41.length;i++){
							
							int type=0;
							if(str41[i].equals("应收")){
								type=1;
							}
							if(str41[i].equals("应付")){
								type=0;
							}
							
						
						RmDTD rmd =  lrs.selectby2(type, str42[i]);
							
						ReceivepayManger rm = new ReceivepayManger();
						
							rm.setId(Integer.parseInt(str40[i]));
							rm.setSubjectcode(rmd.getSubjectcode());
							rm.setSubjectname(rmd.getSubjectname());
							rm.setRemark(rmd.getRemark());
							rm.setType(type);
							rm.setCorp(str42[i]);
							rm.setAmount(str43[i]);
							rm.setIsno(lsh);
							rm.setCorpid(cropid);
							rm.setZhuangtai("0");
							listrm.add(rm);
							
						}
					}else{
						int type=0;
						if(str41[0].equals("应收")){
							type=1;
						}
						if(str41[0].equals("应付")){
							type=0;
						}
						RmDTD rmd =  lrs.selectby2(type, str42[0]);
						
						ReceivepayManger rm = new ReceivepayManger();
						
							rm.setId(Integer.parseInt(str40[0]));
							rm.setSubjectcode(rmd.getSubjectcode());
							rm.setSubjectname(rmd.getSubjectname());
							rm.setRemark(rmd.getRemark());
							rm.setType(type);
							rm.setCorp(str42[0]);
							rm.setAmount(str43[0]);
							rm.setIsno(lsh);
							rm.setCorpid(cropid);
							rm.setZhuangtai("0");
							listrm.add(rm);
					}
					
				}
				

		}
			 int p = 0;
			 int a =0;
			 int l =0;
		
			
		

						for(int j =0;j<listbs.size();j++){
							p=	billser.updateBs(listbs.get(j));
							if(p==0){
								break;
							}
						}

			 

			//System.out.println("==========================================================");
			if(g31.equals("1,")){
				
			}else{
			for(int k =0;k<listsl.size();k++){
				a = ss.updatess(listsl.get(k));
				if(a==0){
					break;
				}
			}
			}
			//System.out.println("==========================================================");
		if(g41.equals("1,")){
			
		}else{
			for(int z =0;z<listrm.size();z++){
				ReceivepayManger rm = listrm.get(z);
				System.out.println(rm.toString());
				l = lrs.updateRp(listrm.get(z));
				if(l==0){
					break;
				}
			}
		}	
			if(p>0&&o>0){
			
				map.put("data", "0");
			}
			localtransactionManager.commit(status);
			} 
		}catch (Exception e) {
			// TODO: handle exception
			localtransactionManager.rollback(status);
			e.printStackTrace();
			map.put("data", "1");
			return map;
		
			}
			
		return map;
		
	}
	
	@RequestMapping(value="/save/settle")
	@ResponseBody
	public Object savesettle(String lsh,String cropid,String settlement,String mingxi,String amount,String tips,String id){
		Settlestyle s  = ss.selectbys(settlement);
		if(mingxi==""||mingxi=="null"||mingxi==null||mingxi.equals("1")){
			s.setMingxi("");
		}else{
			s.setMingxi(mingxi);
		}
		if(tips==""||tips=="null"||tips==null||tips.equals("1")){
			s.setTips("");
		}else{
			s.setTips(tips);
		}
		s.setCropid(cropid);
		s.setIsno(lsh);
		s.setAmount(amount);
		s.setSettlement(settlement);
		s.setZhuangtai("0");
		System.out.println(id);
		if(id.equals("")||id==null||id=="null"){
			
		}else{
		s.setId(Integer.parseInt(id));
		}
		return ss.saveSettle(s);
	}
}
